

package fss.common.communication;

import fss.util.rmi.RmiId;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author Meagan Griffin
 */
public class Status implements Serializable{
  
  private HashMap<RmiId, EServiceType> mConnections;
  
  /**
   * constructor Status()
   *   Creates a new Status object.
   */
  public Status(){
    this.mConnections = new HashMap<RmiId, EServiceType>();
  } // end constructor Status
  
  /**
   * method addConnection(RmiId aRmiId, ERemoteType aServiceType)
   *   Adds a remote connection to the map of remote connections.
   * @param aRmiId RmiId The RmiId of the connection to be added.
   * @param aServiceType EServiceType The type of service of the connection 
   *                                  being added.
   * @return boolean True if this service was successfully added, False if this 
   *                 service is already contained within the map.
   */
  public boolean addConnection(RmiId aRmiId, EServiceType aServiceType)
  {
    if(this.mConnections.containsKey(aRmiId))
    {
      return false;
    }
    else {
      this.mConnections.put(aRmiId, aServiceType);
      return true;
    }
  } // end method addConnection
  
  /**
   * method removeConnection(RmiId aRmiId)
   *   Removes a connection from the connection map.
   * @param aRmiId RmiId The remote service ID of the connection to be removed.
   * @return boolean True if this connection was successfully removed, False if 
   *                 this connection was not in the connection list.
   */
  public boolean removeConnection(RmiId aRmiId)
  {
    if(this.mConnections.containsKey(aRmiId))
    {
      this.mConnections.remove(aRmiId);
      return true;
    }
    else
    {
      return false;
    }
  } // end method removeConnection
  
  /**
   * method getNumConnections()
   *   Returns the number of remote connections this service has.
   * @return int The number of remote connections this service has.
   */
  public int getNumConnections()
  {
    return this.mConnections.keySet().size();
  } // end method getNumConnections
  
  /**
   * method getConnectionIds()
   *   Returns the list of remote services this service is connected to.
   * @return List<RmiId> The list of this service's remote connections.
   */
  public List<RmiId> getConnectionIds()
  {
    List<RmiId> tIdList = new ArrayList<RmiId>();
    for (RmiId tId : this.mConnections.keySet())
    {
      tIdList.add(tId);
    }
    return tIdList;
  } // end method getConnectionIds
  
  /**
   * method getServiceType(RmiId aRmiId)
   *   Returns the service type for this RmiId.
   * @param aRmiId RmiId The RmiId to be evaluated.
   * @return EServiceType The service type of the parameter RmiId.
   */
  public EServiceType getServiceType(RmiId aRmiId)
  {
    return this.mConnections.get(aRmiId);
  } // end method getServiceType
          
  /**
   * enum EServiceType
   *   The enumeration of remote service types.
   */
  public static enum EServiceType{
    CLIENT,
    FILE_SERVICE, 
    REGISTRY;
  } // end enum EServiceType
} // end class Status
